<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>实验室助理工作管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/style.min.css}">
    <!--对话框-->
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.css}">
</head>
<body>

<!--页面主要内容-->
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h4>审核招聘计划申请信息</h4></div>
            <div class="card-header">
                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-10">
                            <form class="form-inline" action="/searchInstructor" >
                                <div class="form-group">
                                    <label class="sr-only" for="example-if-email">搜索</label>
                                    <input class="form-control" type="text" id="example-if-email" name="name" placeholder="search..">
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-default" type="submit">搜索</button>
                                </div>
                            </form>
                        </div>
                        <div class="col-xs-1">
                            <a class="btn btn-yellow m-r-5" href="/toStudentOffice"><i class="mdi mdi-refresh"></i>刷新</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>计划编号</th>
                        <th>计划名称</th>
                        <th>岗位</th>
                        <th>岗位要求</th>
                        <th>招聘人数</th>
                        <th>申请部门</th>
                        <th>申请人</th>
                        <th>开始时间</th>
                        <th>截至时间</th>
                        <th>审核状态</th>
                        <th>审核意见</th>
                        <th>审核是否通过</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tb_teacher">
                    </tbody>
                </table>
            </div>

            <!-- 模态框 -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">审核招聘计划申请信息</h4>
                        </div>
                        <div class="modal-body">

                            <!--页面主要内容-->
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <form action=""  class="row" id="userForm" name="myform">
                                                <input id="planId" type="text" hidden>
                                                <input id="status" type="text" value="1" hidden>
                                                <div class="form-group col-md-12">
                                                    <label for="recruitsNumber">确认招聘人数</label>
                                                    <input type="text" class="form-control" id="recruitsNumber" name="recruitsNumber" value="" placeholder="(不同意可以不填)" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="auditOpinion">审核意见</label>
                                                    <input type="text" class="form-control" id="auditOpinion" name="auditOpinion" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label>审核是否通过</label>
                                                    <div class="example-box">
                                                        <label class="lyear-radio radio-inline radio-primary">
                                                            <input type="radio" name="isOpinion1" value="1" checked><span>同意</span>
                                                        </label>
                                                        <label class="lyear-radio radio-inline radio-primary">
                                                            <input type="radio" name="isOpinion1" value="0" ><span>不同意</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            </form>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--End 页面主要内容-->
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" onclick="modify()">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--End 页面主要内容-->

<script type="text/javascript" th:src="@{/js/jquery-3.6.0.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/main.min.js}"></script>
<!--消息提示-->
<script th:src="@{/Light-Year-Admin/js/bootstrap-notify.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/lightyear.js}"></script>
<!--对话框-->
<script th:src="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.js}"></script>

<script type="text/javascript">

    $(function () {
        // 查询所有数据
        getRecruitmentPlan();
    });

    // 查询所有数据
    function getRecruitmentPlan() {
        $.ajax({
                type: "GET",
                url: "/recruitmentPlan/findAll",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                success: function (result) {
                    let html = "";
                    let statusStr = ''; // 审核状态
                    let isOpinionStr = ''; // 审核意见
                    let auditOpinion = ''; //审核是否通过
                    //遍历结果集result,
                    for(let i = 0,j=1;i<result.length;i++,j++){
                        // 判断审核状态
                        if (result[i].status == 1){
                            statusStr = '已审核';
                            auditOpinion = result[i].auditOpinion;
                        }else {
                            statusStr = '未审核';
                            auditOpinion = '';
                        }
                        // 判断审核是否通过
                        if (result[i].isOpinion == 1){
                            isOpinionStr = '已通过';
                        }else if (result[i].isOpinion == 0){
                            isOpinionStr = '未通过';
                        }else {
                            isOpinionStr = '';
                        }

                        html += "<tr>"+
                            "<td>"+j+"</td>"+
                            "<td>"+result[i].planId+"</td>"+
                            '<td>'+result[i].planName+"</td>"+
                            '<td>'+result[i].wordName+"</td>"+
                            "<td>"+result[i].jobRequirements+"</td>"+
                            "<td>"+result[i].recruitsNumber+"</td>"+
                            "<td>"+result[i].deptName+"</td>"+
                            "<td>"+result[i].applicant+"</td>"+
                            "<td>"+result[i].startTime+"</td>"+
                            "<td>"+result[i].endTime+"</td>"+
                            "<td>"+statusStr+"</td>"+
                            "<td>"+auditOpinion+"</td>"+
                            "<td>"+isOpinionStr+"</td>"+
                            '<td>'+'<a class="btn btn-info btn-sm" role="button" href="javascript:edit(\''+result[i].planId+'\')"><i class="mdi mdi-pencil"></i>审核'+'</a></td>'+
                            "</tr>";
                    }

                    //将html标签拼接在html中
                    $("#tb_teacher").html(html);
                }
            }
        )
    }

    // 新增or修改
    function modify() {
        //获取模态框数据
        var planId = $("#planId").val();
        var status = $("#status").val();
        var recruitsNumber = $("#recruitsNumber").val();
        var auditOpinion = $("#auditOpinion").val();
        // 获取单选框的值---审核是否通过（1通过、0未通过）
        var isOpinion = $('input[type=radio][name=isOpinion1]:checked').val();
        var param = {"planId": planId, recruitsNumber: recruitsNumber, auditOpinion: auditOpinion,isOpinion:isOpinion,status:status};
        $.ajax({
            url: "/recruitmentPlan/update",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(param),
            success: function (data) {
                if(data.code == 200 ){
                    reset();
                    $('#myModal').modal('hide');
                    getRecruitmentPlan();
                }else{
                    alert("失败")
                }
            }
        });
    }

    // 打开审核页面
    function edit(planId) {
        reset();
        // 向模态框中传入planId
        $('#planId').val(planId);
        $('#myModal').modal('show');
    }

    // 清空模态框
    function reset() {
        $("#planId").val("");
        $("#recruitsNumber").val("");
        $("#auditOpinion").val("");
        //$('input[name="isOpinion"]:checked').val("");
    }

</script>
</body>
</html>